package main

import (
	"fmt"
	"reflect"
	"sync"
)

type N int
type X struct {

}
type data struct {
	sync.Mutex
	buf [1024]byte
}
type user struct {

}
type manager struct {
	user
}
type S struct {

}
type T struct {
	S //匿名嵌入字段
}

func (n N) toString() string {
	return fmt.Sprintf("%#x", n)
}

//值参数
func (n N) value() {
	n++
	fmt.Printf("v:%p,%v\n", &n, n)
}

//指针参数
func (n *N) point() {
	*n++
	fmt.Printf("p:%p,%v\n",n,*n)
}

func (n N) test(){
	fmt.Printf("test.n:%p,%d\n",&n,n)
}

//空结构体
func (x *X) methodsTest(){
	println("hi ni",x)
}

func (user) toString() string {
	return "hi user"
}

func (m manager) toString() string {
	return m.user.toString()+"; manager"
}

func (S) sVal(){
}
func (*S) sPtr() {

}
func (T) tVal() {

}
func (*T) tPtr(){

}

func main() {
	valueTest()
	return

	pressTest()
	return

	var t T
	methodSetTest(t)
	println("-----------")
	methodSetTest(&t)
	return

	ovTest()
	nimTest()

	var a N = 25
	p := &a //指针
	println(a.toString())
	a.value()
	a.point()
	fmt.Printf("a:%p,%v\n",&a,a)

	p.value()
	p.point()

	var b *X
	b.methodsTest()
}

//匿名字段
func nimTest()  {
	d := data{}
	d.Lock()
	println("locks")
	defer d.Unlock()
}

//方法覆盖
func ovTest()  {
	var m manager
	println(m.toString())
	println(m.user.toString())
}

//方法集 (todo 有点问题)
func methodSetTest(a interface{})  {

	rs := reflect.TypeOf(a)
	println(rs.Kind())

	for i,n := 0,rs.NumMethod(); i < n; i++  {
		m := rs.Method(i)
		fmt.Println(m.Name)
	}
}

func pressTest()  {
	var n N = 25
	fmt.Printf("presstest：%p,%d\n",&n,n)

	f1 := N.test
	f1(n)
	N.test(n)

	f2 := (*N).test
	f2(&n)
	(*N).test(&n)
}

func valueTest()  {
	var n N = 100
	p := &n

	n++
	f1 := n.test

	n++
	f2 := p.test

	n++
	fmt.Printf("valueTest:%p,%d\n",p,n)

	f1()
	f2()
}